<?php

class FP_Application_Subsystem_View implements FP_Application_Subsystem_Interface {

    public static $view = null;

    protected $_config = null;

    protected $_view_suffix = 'html';

    public function init($pConfig=null){

	$this->_config = $pConfig;

	Zend_Layout::startMvc();
	Zend_Layout::getMvcInstance()->setViewSuffix($this->_view_suffix);

	$ns = FP_Application::getNamespace();

	$template_cachedir = FP_Application::get('cachedir') . '/templates';

	if (!file_exists($template_cachedir) || !is_dir($template_cachedir))
	    mkdir($template_cachedir);

	$engine = new FP_View_Phptal(array('compileDir' => $template_cachedir, 'stripComments' => false ));
	$engine->addBasePath(realpath(BASE_DIR . 'app/views/'),  "{$ns}_View");
	$engine->addHelperPath(realpath(BASE_DIR . 'lib/FP/View/Helper/'), 'FP_View_Helper');

	$engine->assign('server', FP_Application::get('server'));
	$engine->assign('baseUrl', FP_Application::get('baseUrl'));
	$engine->assign('assets', FP_Application::get('assets'));
	$engine->assign('images', FP_Application::get('assets') . '/images');
	$engine->assign('styles', FP_Application::get('assets') . '/styles');
	$engine->assign('scripts', FP_Application::get('assets') . '/scripts');

	if (FP_Application::hasIdentity())
	    $engine->assign('silk_identity', FP_Application::getIdentity());

	$renderer = new Zend_Controller_Action_Helper_ViewRenderer();
	$renderer->setView($engine);
	$renderer->setViewSuffix($this->_view_suffix);
	Zend_Controller_Action_HelperBroker::addHelper($renderer);

	$DocTypeHelper = new Zend_View_Helper_Doctype();
	$DocTypeHelper->doctype('XHTML1_STRICT');

	self::$view = $engine;

    }

}


?>